import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
/**
 * 路由的按需加载
 */
const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login')
  },
  {
    path: '/',
    // 因为当某个路由有子级路由的时候，这时候父级路由需要一个默认的路由，所以父级路由不能定义name属性
    component: () => import('@/views/Layout'),
    children: [
      { path: '', meta: { isKeepAlive: true }, component: () => import('@/views/home') }, // 默认显示的子路由
      { path: '/video', component: () => import('@/views/video') },
      { path: '/question', component: () => import('@/views/question') },
      { path: '/user', component: () => import('@/views/user') }
    ]
  },
  {
    path: '/user/profile',
    name: 'userProfile',
    component: () => import('@/views/user/profile.vue')
  },
  {
    path: '/user/chat',
    name: 'chat',
    component: () => import('@/views/user/chat.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search')
  },
  // 搜索结果页
  {
    path: '/search/result',
    name: 'searchResult',
    component: () => import('@/views/search/result.vue')
  },
  {
    path: '/article/',
    name: 'article',
    component: () => import('@/views/article')
  }
]

const router = new VueRouter({
  routes
})

export default router
